package com.jsmtr.rms.service.impl;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.jsmtr.rms.dao.DaoService;
import com.jsmtr.rms.entity.DUserResume;
import com.jsmtr.rms.entity.HRGXUser;
import com.jsmtr.rms.entity.ProjectInfo;
import com.jsmtr.rms.entity.ProjectInfoFlow;
import com.jsmtr.rms.entity.UserResume;
import com.jsmtr.rms.service.IDoGXService;
import com.jsmtr.rms.utils.BeanTools;
import com.jsmtr.rms.utils.StringTools;
import com.jsmtr.rms.utils.db.DbUtil;

@Service
public class DoGXService implements IDoGXService {

    @Resource
    private DaoService dao;

    public void setDao(DaoService dao) {
        this.dao = dao;
    }

    @Override
    public ProjectInfoFlow getNextFlow(String pid, String deptcode, String fid) throws Exception {
        StringBuilder hql = new StringBuilder("from ProjectInfoFlow where pid='" + pid + "' and deptcode='" + deptcode + "' ");
        hql.append("and forder>(select forder from ProjectInfoFlow where id='" + fid + "') order by forder");
        return (ProjectInfoFlow) dao.findFirst(hql.toString());
    }

    @Override
    public ProjectInfoFlow getCurrentFlow(String pid, String deptcode, String fid) throws Exception {
        return (ProjectInfoFlow) dao.findUnique("from ProjectInfoFlow where pid='" + pid + "' and deptcode='" + deptcode + "' and id='" + fid + "'");
    }

    @Override
    public ProjectInfoFlow getCurrentFlow(String fid) throws Exception {
        return (ProjectInfoFlow) dao.findFirst("from ProjectInfoFlow where id='" + fid + "'");
    }

    @SuppressWarnings("unchecked")
    @Override
    public Map<String, Object> getResumes(int page, int perpage, DUserResume resume, Map<String, Object> param) throws Exception {
        Map<String, Object> map = new HashMap<String, Object>();
        StringBuffer queryHQL = new StringBuffer("from DUserResume r where 1=1 ");
        StringBuffer countHQL = new StringBuffer("select count(*) from DUserResume r where 1=1 ");
        StringBuffer condition = new StringBuffer();

        Object agefrom = param.get("agefrom");
        Object ageto = param.get("ageto");
        Object heightfrom = param.get("heightfrom");
        Object heightto = param.get("heightto");
        Object rcount = param.get("rcount");

        Map<String, Object> _map = new HashMap<String, Object>();

        Calendar cal = Calendar.getInstance();
        if (StringTools.notEmpty(agefrom)) {
            cal.setTime(new Date());
            cal.add(Calendar.YEAR, 0 - Integer.parseInt(agefrom.toString()));
            String _date = cal.get(Calendar.YEAR) + "-" + cal.get(Calendar.MONTH) + "-" + cal.get(Calendar.DATE);
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            _map.put("agefrom", sdf.parse(_date));
            condition.append(" and r.birthday<=:agefrom");
        }
        if (StringTools.notEmpty(ageto)) {
            cal.setTime(new Date());
            cal.add(Calendar.YEAR, 0 - Integer.parseInt(ageto.toString()));
            String _date = cal.get(Calendar.YEAR) + "-" + cal.get(Calendar.MONTH) + "-" + cal.get(Calendar.DATE);
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            _map.put("ageto", sdf.parse(_date));
            condition.append(" and r.birthday>=:ageto");
        }
        if (StringTools.notEmpty(heightfrom)) {
            _map.put("heightfrom", Integer.parseInt(heightfrom.toString()));
            condition.append(" and r.height>=:heightfrom");
        }
        if (StringTools.notEmpty(heightto)) {
            _map.put("heightto", Integer.parseInt(heightto.toString()));
            condition.append(" and r.height<=:heightto");
        }
        resume.setRcount(null);
        if (StringTools.notEmpty(rcount)&&Integer.parseInt(rcount.toString())>0){
            _map.put("rcount", Integer.parseInt(rcount.toString()));
            condition.append(" and  nvl(r.rcount,0) > :rcount");
        }
        condition.append(" and fqstate!='已放弃' ");
        condition.append(BeanTools.hqlWhere(resume, "r"));

        queryHQL.append(condition);
        countHQL.append(condition);

        double count = ((Long) dao.findUnique(countHQL.toString(), _map)).doubleValue();
        double pageCount = Math.ceil(count / (double) perpage);

        List<DUserResume> list = dao.findLimit(queryHQL.toString(), _map, perpage * (page - 1), perpage);

        map.put("pageCount", pageCount);
        map.put("count", count);
        map.put("list", list);
        return map;
    }

    @SuppressWarnings("unchecked")
    @Override
    public List<DUserResume> getResumes(String[] ids) throws Exception {
        return dao.find("from DUserResume where id in(:idlist)", ids);
    }

    @SuppressWarnings("unchecked")
    @Override
    public List<Object[]> getResumes(String code) throws Exception {
        StringBuffer queryHQL = new StringBuffer("select distinct(proid),code,name,proname from DUserResume where code='" + code + "' ");
        List<Object[]> list = dao.find(queryHQL.toString());
        return list;
    }

    @Override
    public DUserResume getDUserResume(String id) throws Exception {
        return (DUserResume) dao.findUnique("from DUserResume where id='" + id + "'");
    }

    @SuppressWarnings("unchecked")
    @Override
    public Map<String, Object> getTjResumes(DUserResume resume, Map<String, Object> param) throws Exception {
        Map<String, Object> map = new HashMap<String, Object>();
        //StringBuffer queryHQL = new StringBuffer("from DUserResume r where 1=1 ");
        StringBuffer queryHQL = new StringBuffer("select r.id,r.name,r.sexname,r.cardno,r.majorname from DUserResume r where 1=1 ");
        StringBuffer condition = new StringBuffer();

        Object agefrom = param.get("agefrom");
        Object ageto = param.get("ageto");
        Object heightfrom = param.get("heightfrom");
        Object heightto = param.get("heightto");

        Map<String, Object> _map = new HashMap<String, Object>();

        Calendar cal = Calendar.getInstance();
        if (StringTools.notEmpty(agefrom)) {
            cal.setTime(new Date());
            cal.add(Calendar.YEAR, 0 - Integer.parseInt(agefrom.toString()));
            String _date = cal.get(Calendar.YEAR) + "-" + cal.get(Calendar.MONTH) + "-" + cal.get(Calendar.DATE);
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            _map.put("agefrom", sdf.parse(_date));
            condition.append(" and r.birthday<=:agefrom");
        }
        if (StringTools.notEmpty(ageto)) {
            cal.setTime(new Date());
            cal.add(Calendar.YEAR, 0 - Integer.parseInt(ageto.toString()));
            String _date = cal.get(Calendar.YEAR) + "-" + cal.get(Calendar.MONTH) + "-" + cal.get(Calendar.DATE);
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            _map.put("ageto", sdf.parse(_date));
            condition.append(" and r.birthday>=:ageto");
        }
        if (StringTools.notEmpty(heightfrom)) {
            _map.put("heightfrom", Integer.parseInt(heightfrom.toString()));
            condition.append(" and r.height>=:heightfrom");
        }
        if (StringTools.notEmpty(heightto)) {
            _map.put("heightto", Integer.parseInt(heightto.toString()));
            condition.append(" and r.height<=:heightto");
        }

        condition.append(BeanTools.hqlWhere(resume, "r"));

        queryHQL.append(condition);

        List<DUserResume> list = dao.find(queryHQL.toString(), _map);

        map.put("list", list);
        return map;
    }

    @Override
    public Map<String, Object> getMSUsers(int page, int perpage, DUserResume user, Map<String, Object> param) throws Exception {

        StringBuffer queryHQL = new StringBuffer("select r.id,s.id as msuserid,r.code,r.name,r.cardno,r.university,r.majorname,r.educationname,s.starttime,s.address,s.notice,s.point,s.result,r.fid,r.fqstate,r.jname,s.op7,c.confirmtime,c.isconfirm,s.scoringrules,cardnototal.cardcount,hru.logintime,m.id mid,m.content mcontent,r.nrid,r.njname, r.msarrange ");

        StringBuffer countHQL = new StringBuffer("select count(1) ");
        StringBuffer condition = new StringBuffer();
        condition.append(" from (select * from DoMS_User u where u.fid = '" + param.get("flowid").toString() + "') s,duserresume r,(select count(1) cardcount, r.cardno from duserresume r group by r.cardno) cardnototal,DoMS_Confirm c ,HR_USER hru,( select * from  Duserremark dm where  dm.fid like '%"+ user.getPath()+"%'" + "   and dm.pid like '%"+user.getProid()+"%' ) m where r.id=s.userid(+) and r.id=m.rid(+) and s.id=c.msuserid(+) and r.userid=hru.id(+) and r.cardno = cardnototal.cardno(+) ");

        Object agefrom = param.get("agefrom");
        Object ageto = param.get("ageto");
        Object heightfrom = param.get("heightfrom");
        Object heightto = param.get("heightto");

        Calendar cal = Calendar.getInstance();
        if (StringTools.notEmpty(agefrom)) {
            cal.setTime(new Date());
            cal.add(Calendar.YEAR, 0 - Integer.parseInt(agefrom.toString()));
            String _date = cal.get(Calendar.YEAR) + "-" + cal.get(Calendar.MONTH) + "-" + cal.get(Calendar.DATE);
            condition.append(" and r.birthday<=to_date('" + _date + "','yyyy-mm-dd')");
        }

        if (StringTools.notEmpty(ageto)) {
            cal.setTime(new Date());
            cal.add(Calendar.YEAR, 0 - Integer.parseInt(ageto.toString()));
            String _date = cal.get(Calendar.YEAR) + "-" + cal.get(Calendar.MONTH) + "-" + cal.get(Calendar.DATE);
            condition.append(" and r.birthday>=to_date('" + _date + "','yyyy-mm-dd')");
        }
        if (StringTools.notEmpty(heightfrom)) {
            condition.append(" and r.height>='" + Integer.parseInt(heightfrom.toString()) + "'");
        }
        if (StringTools.notEmpty(heightto)) {
            condition.append(" and r.height<='" + Integer.parseInt(heightto.toString()) + "'");
        }

        Object result = param.get("msresult");
        if (StringTools.trimNotEmpty(result)) {
            condition.append(" and s.result='" + result + "' ");
        }

        int notice = Integer.parseInt(param.get("notice").toString());
        if (notice != -1) {
            condition.append(" and s.notice='" + notice + "' ");
        }

        if (StringTools.notEmpty(param.get("isconfirm").toString())) {
            condition.append(" and c.isconfirm='" + param.get("isconfirm").toString() + "'");
        }

        if (StringTools.notEmpty(param.get("msplan"))) {
            String msaddress=param.get("msplan").toString();
            if(msaddress.equalsIgnoreCase("yes")){
                condition.append(" and s.address  is not null ");
            }else{
                condition.append(" and s.address  is null ");
            }
        }

        if (StringTools.notEmpty(param.get("msplantime"))) {
            String msplantime=param.get("msplantime").toString();
            condition.append(" and s.starttime like '%"+msplantime+"%'");
        }

        if (StringTools.notEmpty(param.get("msaddress"))) {
            String msaddress=param.get("msaddress").toString();
            condition.append(" and s.address like '%"+msaddress+"%'");
        }

        Object ischangejob = param.get("ischangejob");
        if (StringTools.notEmpty(ischangejob)){
            if (ischangejob.toString().equalsIgnoreCase("是")){
                condition.append(" and  r.njname is not null ");
            }else  if (ischangejob.toString().equalsIgnoreCase("否")){
                condition.append(" and  r.njname is  null ");
            }

        }

        //2019-11-6 新增成绩区间条件筛选
        Object scorearea =param.get("scorearea");
        if (StringTools.notEmpty(param.get("scorearea"))) {
            if (scorearea.toString().equalsIgnoreCase("L60")){
                condition.append(" and to_number(nvl(s.point,0))  <60 ");
            }else if(scorearea.toString().equalsIgnoreCase("R60")){
                condition.append(" and to_number(nvl(s.point,0))  >=60 ");
            }

        }

        condition.append(BeanTools.hqlWhere(user, "r"));
        condition.append( " order by nvl(s.point,0) desc");
        queryHQL.append(condition);
        countHQL.append(condition);
       // System.out.println(queryHQL);

       // return DbUtil.pageSqlQuery(page, perpage, queryHQL.toString(), countHQL.toString(), dao);
        return  DbUtil.pageSqlQueryMap(page,perpage,queryHQL.toString(),null,countHQL.toString(),dao);
    }

    @Override
    public Map<String, Object> getPostUsers(int page, int perpage, DUserResume user, Map<String, Object> param) throws Exception {
        StringBuffer queryHQL = new StringBuffer("select r.id,r.code,r.name,r.sexname,r.cardaddress,r.university,r.majorname,r.educationname,r.tel,s.point,r.jname,r.gwstate,r.fid,r.fqstate,r.op6 ");

        StringBuffer countHQL = new StringBuffer("select count(1) ");
        StringBuffer condition = new StringBuffer();
        condition.append("from DoMS_User s,duserresume r where r.id=s.userid(+) ");

        Object agefrom = param.get("agefrom");
        Object ageto = param.get("ageto");
        Object heightfrom = param.get("heightfrom");
        Object heightto = param.get("heightto");

        Calendar cal = Calendar.getInstance();
        if (StringTools.notEmpty(agefrom)) {
            cal.setTime(new Date());
            cal.add(Calendar.YEAR, 0 - Integer.parseInt(agefrom.toString()));
            String _date = cal.get(Calendar.YEAR) + "-" + cal.get(Calendar.MONTH) + "-" + cal.get(Calendar.DATE);
            condition.append(" and r.birthday<=to_date('" + _date + "','yyyy-mm-dd')");
        }
        if (StringTools.notEmpty(ageto)) {
            cal.setTime(new Date());
            cal.add(Calendar.YEAR, 0 - Integer.parseInt(ageto.toString()));
            String _date = cal.get(Calendar.YEAR) + "-" + cal.get(Calendar.MONTH) + "-" + cal.get(Calendar.DATE);
            condition.append(" and r.birthday>=to_date('" + _date + "','yyyy-mm-dd')");
        }
        if (StringTools.notEmpty(heightfrom)) {
            condition.append(" and r.height>='" + Integer.parseInt(heightfrom.toString()) + "'");
        }
        if (StringTools.notEmpty(heightto)) {
            condition.append(" and r.height<='" + Integer.parseInt(heightto.toString()) + "'");
        }

        Object result = param.get("msresult");
        if (StringTools.trimNotEmpty(result)) {
            condition.append(" and s.result='" + result + "' ");
        }

        condition.append(BeanTools.hqlWhere(user, "r"));

        queryHQL.append(condition).append(" order by s.point desc ");
        countHQL.append(condition);

        System.out.println(queryHQL);

        return DbUtil.pageSqlQuery(page, perpage, queryHQL.toString(), countHQL.toString(), dao);
    }


    @Override
    public HRGXUser getUser(String pid, String code) throws Exception {
        return (HRGXUser) dao.findFirst("from HRGXUser where pid='" + pid + "' and code='" + code + "'");
    }

    @SuppressWarnings("unchecked")
    @Override
    public List<HRGXUser> getUsers(String pid, String[] ids) throws Exception {
        return dao.find("from HRGXUser where pid='" + pid + "' and id in(:idlist)", ids);
    }

    @Override
    public Map<String, Object> getUserResumes(int page, int perpage, UserResume resume) throws Exception {
        StringBuffer queryHQL = new StringBuffer("from UserResume r where 1=1 ");
        StringBuffer countHQL = new StringBuffer("select count(*) from UserResume r where 1=1 ");
        StringBuffer condition = new StringBuffer();
        condition.append(BeanTools.hqlWhere(resume, "r"));

        queryHQL.append(condition);
        countHQL.append(condition);

        return DbUtil.pageQuery(page, perpage, queryHQL.toString(), countHQL.toString(), dao);
    }

    @Override
    public DUserResume getDResume(String userid, String proid) throws Exception {
        return (DUserResume) dao.findUnique("from DUserResume where proid='" + proid + "' and userid='" + userid + "'");
    }

    @Override
    public UserResume getResume(String userid) throws Exception {
        return (UserResume) dao.findUnique("from UserResume where userid='" + userid + "'");
    }

    @Override
    public ProjectInfo getProject(String id) throws Exception {
        return (ProjectInfo) dao.findUnique("from ProjectInfo where id='" + id + "'");
    }
	
	/*@Override
	public synchronized List<String> CreateResumeCodes(PlanInfo planInfo,int count) {
		try {
			String code = planInfo.getPcode();
			int size = ((Long) dao.findUnique("select count(*) from DUserResume where pid='" + planInfo.getId() + "'")).intValue();
            DecimalFormat df = new DecimalFormat("00000");
            
			List<String> codes = new ArrayList<String>();
			for (int i = 1; i <= count; i++) {
				codes.add(code + "-" + df.format(i + size));
			}
			return codes;
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}*/

    @Override
    public Map<String, Object> getUsers(int page, int perpage, HRGXUser user) throws Exception {
        StringBuffer queryHQL = new StringBuffer("from HRGXUser r where 1=1 ");
        StringBuffer countHQL = new StringBuffer("select count(*) from HRGXUser r where 1=1 ");
        StringBuffer condition = new StringBuffer();
        condition.append(BeanTools.hqlWhere(user, "r"));

        queryHQL.append(condition);
        countHQL.append(condition);

        return DbUtil.pageQuery(page, perpage, queryHQL.toString(), countHQL.toString(), dao);
    }

    @Override
    public HRGXUser getUser(String id) throws Exception {
        return (HRGXUser) dao.findUnique("from HRGXUser where id='" + id + "'");
    }

    @Override
    public int getZSUserCount(String pid, String zsstate) {
        try {
            String hql = "select count(*) from HRGXUser where pid='" + pid + "' and zsstate='" + zsstate + "'";
            return ((Long) dao.findUnique(hql)).intValue();
        } catch (Exception e) {
            e.printStackTrace();
            return -1;
        }
    }

    @SuppressWarnings("unchecked")
    @Override
    public List<String> getTjTimeList(String pid) throws Exception {
        return dao.executeSQLQuery("select distinct(tjtime) from HR_GXUser where pid='" + pid + "'");
    }

    @SuppressWarnings("unchecked")
    @Override
    public List<HRGXUser> getTjUsers(String pid, String tjtime) throws Exception {
        return dao.find("from HRGXUser where pid='" + pid + "' and tjtime='" + tjtime + "'");
    }

    @Override
    public int getTJUserCount(String pid, String tjstate, String zsstate) {
        try {
            String hql = "select count(*) from HRGXUser where pid='" + pid
                    + "' and zsstate='" + zsstate + "' and tjstate='" + tjstate + "'";
            return ((Long) dao.findUnique(hql)).intValue();
        } catch (Exception e) {
            e.printStackTrace();
            return -1;
        }
    }

    @Override
    public int getGWUserCount(String pid, String gwstate, String tjstate) {
        try {
            String hql = "select count(*) from HRGXUser where pid='" + pid
                    + "' and tjstate='" + tjstate + "' and gwstate='" + gwstate + "'";
            return ((Long) dao.findUnique(hql)).intValue();
        } catch (Exception e) {
            e.printStackTrace();
            return -1;
        }
    }

    @SuppressWarnings("unchecked")
    @Override
    public List<Object[]> getDemands(String pid) throws Exception {
        String hql = "select j.id,d.jobname from PLAN_PERSONDEMAND d,PROJECT_INFO_JOB j where d.id=j.did and j.pid='" + pid + "'";
        return dao.executeSQLQuery(hql);
    }

    @Override
    public DUserResume getResume(String code, String pid) throws Exception {
        return (DUserResume) dao.findUnique("from DUserResume where cardno='" + code + "' and proid='" + pid + "'");
    }


    @SuppressWarnings("unchecked")
    @Override
    public List<String> getBdTimeList(String pid) throws Exception {
        return dao.executeSQLQuery("select distinct(bdtime) from HR_GXUser where pid='" + pid + "'");
    }

    @SuppressWarnings("unchecked")
    @Override
    public List<HRGXUser> getBdUsers(String pid, String bdtime) throws Exception {
        return dao.find("from HRGXUser where pid='" + pid + "' and bdtime='" + bdtime + "'");
    }

    @SuppressWarnings("unchecked")
    @Override
    public List<Object[]> getBdUserCount(String pid) throws Exception {
        return dao.executeSQLQuery("select count(*),t.jid from DUSERRESUME t where t.proid='" + pid + "' and t.cardno in(select code from hr_gxuser where bdstate='已报到') group by t.jid");
    }

    @Override
    public Map<String, Object> getResumesMap(int page, int perpage, DUserResume resume, Map<String, Object> param) throws Exception {
        Map<String, Object> map = new HashMap<String, Object>();
        StringBuffer queryHQL = new StringBuffer(" select r.*,m.id mid,m.content mcontent, cardnototal.cardcount,hru.logintime,s.point mspoint,s.result msresult  from DUserResume r,(select count(1) cardcount, r.cardno from duserresume r group by r.cardno) cardnototal,( select * from  Duserremark dm where  dm.fid like '%"+resume.getPath().replaceAll("/","")+"%'" + "   and dm.pid like '%"+resume.getProid()+"%' ) m,HR_USER hru,DoMS_User s where 1=1 and r.id=m.rid(+) and r.userid=hru.id(+) and r.id=s.userid(+)  and r.cardno = cardnototal.cardno(+) ");
        StringBuffer countHQL = new StringBuffer("select count(*) from DUserResume r,(select count(1) cardcount, r.cardno from duserresume r group by r.cardno) cardnototal,( select * from  Duserremark dm where  dm.fid like '%"+resume.getPath().replaceAll("/","")+"%'" + "   and dm.pid like '%"+resume.getProid()+"%') m,HR_USER hru,DoMS_User s where 1=1 and r.id=m.rid(+) and r.userid=hru.id(+) and r.id=s.userid(+) and r.cardno = cardnototal.cardno(+)  ");
        StringBuffer condition = new StringBuffer();

        Object agefrom = param.get("agefrom");
        Object ageto = param.get("ageto");
        Object workyearfrom = param.get("workyearfrom");
        Object workyearto = param.get("workyearto");
        Object heightfrom = param.get("heightfrom");
        Object heightto = param.get("heightto");
        Object rcount = param.get("rcount");
        Object usercontent = param.get("usercontent");
        Object resultediter = param.get("resultediter");

        Map<String, Object> _map = new HashMap<String, Object>();

        Calendar cal = Calendar.getInstance();
        if (StringTools.notEmpty(agefrom)) {
            cal.setTime(new Date());
            cal.add(Calendar.YEAR, 0 - Integer.parseInt(agefrom.toString()));
            String _date = cal.get(Calendar.YEAR) + "-" + cal.get(Calendar.MONTH) + "-" + cal.get(Calendar.DATE);
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            _map.put("agefrom", sdf.parse(_date));
            condition.append(" and r.birthday<=:agefrom");
        }
        if (StringTools.notEmpty(ageto)) {
            cal.setTime(new Date());
            cal.add(Calendar.YEAR, 0 - Integer.parseInt(ageto.toString()));
            String _date = cal.get(Calendar.YEAR) + "-" + cal.get(Calendar.MONTH) + "-" + cal.get(Calendar.DATE);
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            _map.put("ageto", sdf.parse(_date));
            condition.append(" and r.birthday>=:ageto");
        }
        if (StringTools.notEmpty(workyearfrom)) {
            _map.put("workyearfrom", Integer.parseInt(workyearfrom.toString()));
            condition.append(" and r.workexperience>=:workyearfrom");
        }
        if (StringTools.notEmpty(workyearto)) {
            _map.put("workyearto", Integer.parseInt(workyearto.toString()));
            condition.append(" and r.workexperience<=:workyearto");
        }
        if (StringTools.notEmpty(heightfrom)) {
            _map.put("heightfrom", Integer.parseInt(heightfrom.toString()));
            condition.append(" and r.height>=:heightfrom");
        }
        if (StringTools.notEmpty(heightto)) {
            _map.put("heightto", Integer.parseInt(heightto.toString()));
            condition.append(" and r.height<=:heightto");
        }


        if (StringTools.notEmpty(rcount)&&Integer.parseInt(rcount.toString())>0){
            _map.put("rcount", Integer.parseInt(rcount.toString()));
            condition.append(" and  nvl(r.rcount,0) >= :rcount");
            resume.setRcount(null);
        }

        if (StringTools.notEmpty(usercontent)){
            if (usercontent.toString().equalsIgnoreCase("已记录")){
                condition.append(" and  m.content is not null ");
            }else  if (usercontent.toString().equalsIgnoreCase("未记录")){
                condition.append(" and  m.content is  null ");
            }

        }

        if (StringTools.notEmpty(resultediter)){
            if (resultediter.toString().equalsIgnoreCase("已记录")){
                condition.append(" and  r.tjuname is not null ");
            }else  if (resultediter.toString().equalsIgnoreCase("未记录")){
                condition.append(" and  r.tjuname is  null ");
            }

        }

        if (StringTools.notEmpty(param.get("msresult"))) {
            condition.append(" and s.result='"+param.get("msresult").toString()+"'");
           // _map.put("msresult", param.get("msresult").toString());
        }
        //2019-11-6 新增成绩区间条件筛选
        Object scorearea =param.get("scorearea");
        if (StringTools.notEmpty(param.get("scorearea"))) {
            if (scorearea.toString().equalsIgnoreCase("L60")){
                condition.append(" and to_number(nvl(s.point,0))  <60 ");
            }else if(scorearea.toString().equalsIgnoreCase("R60")){
                condition.append(" and to_number(nvl(s.point,0))  >=60 ");
            }

        }

        condition.append(BeanTools.hqlWhere(resume, "r"));
        queryHQL.append(condition);
        countHQL.append(condition);

        queryHQL.append(" order  by r.name asc ");
        return DbUtil.pageSqlQueryMap(page,perpage,queryHQL.toString(),_map,countHQL.toString(),dao);
    }


}
